package com.lanyan.system.controller.api;

import com.lanyan.common.annotation.RepeatSubmit;

import java.math.BigDecimal;

import com.lanyan.common.utils.SecurityUtils;
import io.swagger.annotations.Api;

import java.util.List;
import java.util.Date;

import com.lanyan.common.core.domain.R;
import com.lanyan.common.core.domain.PageR;

import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lanyan.common.annotation.Log;
import io.swagger.annotations.ApiOperation;
import com.lanyan.common.core.controller.BaseController;
import com.lanyan.common.core.domain.AjaxResult;
import com.lanyan.common.core.domain.R;
import com.lanyan.common.enums.BusinessType;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import springfox.documentation.annotations.ApiIgnore;
import com.lanyan.common.utils.StringUtils;
import com.lanyan.system.domain.Inform;
import com.lanyan.system.domain.vo.InformVo;
import com.lanyan.system.service.IInformService;
import com.lanyan.common.utils.poi.ExcelUtil;
import com.lanyan.common.core.page.TableDataInfo;

/**
 * 消息通知Controller
 *
 * @author lanyan
 * @date 2024-11-26
 */
@RestController
@Api(tags = {"消息通知"})
@RequestMapping("/api/inform")
public class ApiInformController extends BaseController {
    @Autowired
    private IInformService informService;

    /**
     * 查询消息通知列表
     */
    @GetMapping("/page")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "类型（0系统 1公告 2活动）", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "pageNum", value = "第几页", dataType = "int", dataTypeClass = int.class),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", dataTypeClass = int.class),

    })
    @ApiOperation("查询消息通知列表")
    public PageR<Inform> list(@ApiIgnore Inform inform) {
        Long accountId = SecurityUtils.getUserId();
        informService.lambdaUpdate()
                .eq(InformVo::getDelFlag, "0")
                .eq(InformVo::getAccountId, accountId)
                .set(InformVo::getIsRead, "1")
                .update();
        startPage();
        inform.setAccountId(accountId);
        List<Inform> list = informService.selectInformList(inform);
        return PageR.page(list);
    }

    /**
     * 获取消息通知详细信息
     */
    @GetMapping(value = "/info")
    @ApiOperation("获取消息通知详细信息")
    public R<Inform> getInfo(Long informId) {
        return R.ok(informService.selectInformByInformId(informId));
    }

    /**
     * 获取是否有未读消息
     */
    @GetMapping(value = "/unread")
    @ApiOperation("获取是否有未读消息")
    public R<Boolean> unread() {
        Integer count = informService.lambdaQuery()
                .eq(InformVo::getAccountId, SecurityUtils.getUserId())
                .eq(InformVo::getDelFlag, "0")
                .eq(InformVo::getIsRead, "0")
                .count();
        return R.ok(count != 0);
    }


}
